#!/usr/bin/env bash
set -Eeo pipefail

USER="$(id -u)"

create_directory_if_not_exists() {
    local dir="$1"
    if [ ! -e "$dir" ]; then
        mkdir "$dir"
    fi
}

create_directory_if_not_exists "/home/rocketmq/console-data"

if [ "$USER" -eq 0 ]; then
        chown -R rocketmq:rocketmq /home/rocketmq/console-data
fi

exec gosu rocketmq "$@"
